//
//  SCAgreementController.m
//  Scalper
//
//  Created by 王云 on 2017/9/28.
//  Copyright © 2017年 WY. All rights reserved.
//

#import "SCAgreementController.h"
#import <WebKit/WebKit.h>

@interface SCAgreementController ()<WKUIDelegate,WKNavigationDelegate>

@property (nonatomic,weak)WKWebView *webView;


@end

@implementation SCAgreementController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"商家协议";
    
    [self.view addSubview:self.webView];
    
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[SCAgreementWebUrl stringByAppendingString:@"/faq_detail.html?id=1&simple_mode=1"]]]];
    
    __weak __typeof(&*self)weakSelf = self;
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
}
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    DLog(@"开始");
    [SCTool showLoading:@"正在加载"];
    
}
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
{
    DLog(@"返回数据");
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    self.title = webView.title;
    DLog(@"加载完成");
    [SCTool hideHUD];
    
}
- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error{
    DLog(@"加载失败");
    [SCTool showError:@"加载失败"];
}

- (WKWebView *)webView{
    if (_webView == nil) {
        WKWebView *WebView = [[WKWebView alloc] initWithFrame:self.view.frame];
        WebView.UIDelegate = self;
        WebView.navigationDelegate = self;
        [self.view addSubview:WebView];
        _webView = WebView;
    }
    return _webView;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [SCTool hideHUD];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
